﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.IO;
using System.Text.RegularExpressions;
using System.Text;

using Com.VikingErik.Mvc.ResumingDownloads;

namespace ResumableDownloadTesting.Controllers
{
    [HandleError]
    public class HomeController : ResumingController
    {
        public ActionResult Index()
        {
            ViewData["Message"] = "Welcome to ASP.NET MVC!";
            return View();
        }

        public ActionResult About()
        {
            return View();
        }

        [ResumableDownloadActionFilter("ResumableRequest")]
        public ActionResult Media(ResumableDownloadRequest ResumableRequest, string id)
        {
            if (string.IsNullOrEmpty(id))
            {
                var files = System.IO.Directory.GetFiles(Server.MapPath("/Media")).Select(item => item.Substring(item.LastIndexOf(@"\") + 1)).ToList();
                return View(files);
            }


            FileInfo contentFile = new FileInfo(Server.MapPath("/Media/" + id));
            return new ResumableVideoResult(ResumableRequest, contentFile, "video/mp4");
        }
    }
}
